/*
 * @Author: xiongchao
 * @Date: 2023-08-14 15:00:16
 * @LastEditors: xiongchao
 * @LastEditTime: 2023-08-14 15:36:07
 * @Description: TODO
 */
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/course1'
  },
  {
    path: '/course1',
    name: 'course1',
    component: () => import("../views/threejs/course1.vue"),
    meta: {
      title: 'threejs课程1'
    }
  },
  {
    path: '/course2',
    name: 'course2',
    component: () => import("../views/threejs/course2.vue"),
    meta: {
      title: 'threejs课程2'
    }
  },
  {
    path: '/course3',
    name: 'course3',
    component: () => import("../views/threejs/course3.vue"),
    meta: {
      title: 'threejs课程3'
    }
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

//路由守卫
// router.beforeEach((to,form,next) =>{
//   //动态改变浏览器的标题
//   document.title = to.meta.title
//   next()
//   let user = localStorage.getItem('user')

function isString(value: unknown): value is string {
  return typeof value === "string";
}

router.beforeEach((to, from, next) => {
  document.title = isString(to.meta.title) ? to.meta.title : ""; //动态改变浏览器标题
  next();
});
export default router
